<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
      layout:decorate="layout">
<head>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" />
    <script src="//cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
    <script src="//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    <script th:inline="javascript">
        var cpath = /*[[@{/}]]*/ '';
        var csrf = /*[[${_csrf.token}]]*/ '';
        function doSearch(){
            location.href=cpath+"oauthClient?clientid="+$('#clientid').val();
        }
        function saveApp(){
            $.ajax({
                type:'POST',
                url:cpath+'oauthClient',
                data:{'_csrf':csrf,'client_name':$('#client_name').val(),
                    'redirect_uri':$('#redirect_uri').val()},
                error:function(){
                    alert('请求失败,稍候重试！');
                },
                success:function(msg){
                    if(msg=='SUCCESS'){
                        alert('新增成功！');
                        location.reload();
                    }
                }
            });
        }
    </script>
</head>
<body>
    <div class="container">
        <div class="row form-inline form-group">
            <div class="col-md-6 text-left ">
                <input type="button" class="btn btn-primary" value="新增" data-toggle="modal" data-target="#myModal"/>
            </div>
            <div class="col-md-6 text-right">
                <input type="text" class="form-control" placeholder="client_id" th:value="${clientid}" id="clientid"/>
                <input type="button" class="btn btn-primary" value="搜索" onclick="doSearch()"/>
            </div>
        </div>
        <table class="table table-striped table-bordered">
            <thead class="info">
            <tr>
                <th>#</th>
                <th>应用名称</th>
                <th>应用ID</th>
                <th>应用密钥</th>
                <th>回调地址</th>
                <th>授权方式</th>
                <th>授权域</th>
            </tr>
            </thead>
            <tbody>
            <tr th:each="item,itemStat : ${results}">
                <th scope="row" th:text="${itemStat.count}"></th>
                <td th:text="${item.client_name}"></td>
                <td th:text="${item.client_id}"></td>
                <td th:text="${item.client_secret}"></td>
                <td th:text="${item.web_server_redirect_uri}"></td>
                <td th:text="${item.authorized_grant_types}"></td>
                <td th:text="${item.scope}"></td>
            </tr>
            </tbody>
        </table>
        <div class="row">
            <div class="col-md-4 text-left">
                共<span th:text="${page.total}"></span>条记录
            </div>
            <div class="col-md-8 text-right">
                <div class="btn-group" role="group" aria-label="page" th:if="${page.total}>0">
                    <a class="btn btn-default">Pre</a>
                    <a th:each="pageno : ${page.totalPages}" class="btn btn-default active"
                       th:text="${pageno}"
                        th:href="@{/oauthClient(page=${pageno},clientid=${clientid})}">1</a>
                    <a class="btn btn-default">Next</a>
                </div>
            </div>
        </div>
    </div>

    <!-- Modal -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">新增应用</h4>
                </div>
                <div class="modal-body">
                    <div class="text-center">
                        <form class="form-horizontal">
                            <input type="text" id="client_name" class="form-control" style="margin-bottom: 15px;" placeholder="应用名称" />
                            <input type="text" id="redirect_uri" class="form-control"  style="margin-bottom: 15px;" placeholder="回调地址" />
                        </form>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="saveApp()">添加</button>
                </div>
            </div>
        </div>
    </div>
</body>
</html>